package com.qianfeng.test.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.qianfeng.test.R;
import com.qianfeng.test.bean.ShopInfo;
import com.qianfeng.test.constants.UrlConstans;
import com.qianfeng.test.task.ItemImageTask;
import com.qianfeng.test.utils.ImageLoaderHelper;

import java.util.List;

/**
 * Created by Administrator on 15-7-20.
 */
public class MainItemAdapter extends AppBaseAdapter<ShopInfo>{
    private DisplayImageOptions options;

    public MainItemAdapter(List<ShopInfo> shopInfoList, Context context) {
        super(shopInfoList, context);
        options = ImageLoaderHelper.getInstance().getDisplayImageOptions(R.mipmap.ic_launcher,R.mipmap.ic_launcher);

    }

    @Override
    public View getItemView(int position, View convertView, ViewGroup parent) {
        ViewHolder vh;
        if(convertView==null){
            convertView = inflater.inflate(R.layout.item_main_layout,parent,false);
            vh = new ViewHolder(convertView);
            convertView.setTag(vh);
        }else{
            vh = (ViewHolder) convertView.getTag();
        }

        vh.product.setText(list.get(position).getProduct());
        vh.notice.setText(list.get(position).getNotice());
        vh.img.setImageResource(R.mipmap.ic_launcher);
        vh.img.setTag(list.get(position).getImage());
        String picUrl = UrlConstans.Url_ADD+list.get(position).getImage();
//        ItemImageTask task = new ItemImageTask(vh.img);
//        task.execute(picUrl);
        ImageLoader.getInstance().displayImage(picUrl,vh.img,options);

        return convertView;
    }
    private static class ViewHolder{
        private ImageView img;
        private TextView product;
        private TextView notice;

        public ViewHolder(View convertView) {
            img = (ImageView) convertView.findViewById(R.id.item_main_imageView);
            product = (TextView) convertView.findViewById(R.id.item_main_product);
            notice = (TextView) convertView.findViewById(R.id.item_main_notice);

        }
    }

}
